package com.sinping.qh.api.app.version.v1.login;

import com.sinping.qh.api.app.base.BaseAppEndPoint;
import com.sinping.qh.api.support.Const;
import com.sinping.qh.api.support.ConstEum;
import com.sinping.qh.api.support.ResDto;
import com.sinping.qh.dto.app.user.UserByAppDTO;
import com.sinping.qh.service.app.login.ILoginService;
import com.sinping.qh.utils.mapper.JsonMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangjin
 * @create 2018/5/29
 */
@Api(value = "app登录", description = "app登录API")
@RestController
@RequestMapping(value = Const.BASE_URI, name = "app退出登录")
public class LogOutEndPoint extends BaseAppEndPoint {


    @Autowired
    ILoginService iLoginService;


    @ApiOperation(httpMethod = "PUT", value = "客户通过手机退出登录")
    @RequestMapping(value = "/applogout", name = "用户退出登录", method = RequestMethod.PUT)
    public ResDto loginOut(@ApiParam(name="msg",value="{\"token\":\"123456\"}")
                        @RequestParam(required = true) String msg){
        ResDto resDto = new ResDto(ConstEum.SUCCESS);
        //转换msg数据
        UserByAppDTO userByAppDTO = JsonMapper.INSTANCE.fromJson(msg, UserByAppDTO.class);
        String token = userByAppDTO.getToken();
        //验证必要参数
        checkNull(token,ConstEum.PARAM_ERROR,"Token不可以为空");


        resDto =iLoginService.logout(userByAppDTO);

        return resDto;
    }

}
